<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="商品名称" prop="keyword">
        <el-input
          v-model="queryParams.keyword"
          placeholder="请输入商品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label=""></el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          v-hasPermi="['commodity:localProduct:syn']"
          :loading="subLoading"
          @click="handlesync"
          >同步商品</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row> -->
    <el-table v-loading="loading" :data="productList">
      <el-table-column label="商品供应商" prop="goodsSupplier" align="center">
        <template slot-scope="scope">
          <el-tag type="" effect="dark">{{ scope.row.goodsSupplier }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="商品名称" align="center" prop="productName" />

      <el-table-column label="市场价格" align="center" prop="marketPrice" />
      <el-table-column label="成本价格" align="center" prop="costPrice" />
      <el-table-column label="售价" align="center" prop="shopPrice" />
      <el-table-column label="商品主图">
        <template slot-scope="scope">
          <el-image
            :src="scope.row.previewImg"
            fit="fill"
            :preview-src-list="[scope.row.previewImg]"
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            v-hasPermi="['system:product:detail']"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { localList, synThird } from "@/api/product/localGoods.js";
export default {
  name: "Product",
  data() {
    return {
      subLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商城商品表格数据
      productList: [],
      // 弹出层标题
      title: "",

      categoryName: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: null,
        selectCategoryId: null,
      },
      //议价列表
      bargainList: [],
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  watch: {},
  methods: {
    // 同步三方商品
    handlesync() {
      this.subLoading = true;
      synThird()
        .then((res) => {
          this.subLoading = false;
          this.getList();
          this.$modal.msgSuccess(res.msg);
        })
        .catch((err) => {
          this.subLoading = false;
        });
    },
    /** 查询商城商品列表 */
    getList() {
      this.loading = true;
      const data = {
        ...this.queryParams,
      };
      localList(data).then((response) => {
        this.productList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 跳转详情
    handleDetail(row) {
      const { id } = row;
      this.$router.push({
        path: "localGoodsDetail",
        query: {
          id,
        },
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        bargainId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
